<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.order-time-bg{background-color:#1E9FFF;color:white;padding:0px 5px;}
.layui-laydate-footer{display:none;}
</style>
<div class="fixed-bar">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
		<div class="layui-form-item">	
			<div class="layui-inline">
				<label class="layui-form-label">名称</label>
				<div class="layui-input-inline">
					<input type="text" name="keyword" lay-verify="" placeholder="输入用户名/昵称" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">角色</label>
				<div class="layui-input-inline">
					{:Form::select('role_id', '', $rolesKV, '', '')}
				</div>
			</div>
			<div class="layui-inline">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
			</div>
		</div>
	</form>
</div>

<table id="dataTable"></table>

{include file="block/layui" /}

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?table=admin_user&id={{ d.id }}">
</script>

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('editAuth')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '70%', height: '600px'}">设置权限</a>
    <a href="{:url('editUser')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '470px', height: '400px'}" title="修改管理员">修改</a><a href="{:url('delUser')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('addUser')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '470px', height: '400px'}" title="添加管理员">&nbsp;添加</a>
        <a data-href="{:url('status?val=1')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns layui-icon layui-icon-play" data-table="dataTable">&nbsp;启用</a>
        <a data-href="{:url('status?val=0')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns layui-icon layui-icon-pause" data-table="dataTable">&nbsp;禁用</a>
        <a data-href="{:url('delUser')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</script>

<script type="text/javascript">
    layui.use(['table','jquery', 'tool'], function() {
        var table = layui.table;
        var $ = layui.jquery;
        var factoryKV = {:$factoryKV};
        
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'id', title: 'ID', width: 80}
                ,{field: 'username', title: '用户名', width: 120}
                ,{field: 'nick', title: '昵称', width: 100}
                ,{field: 'role_id', title: '角色', templet:function(d){
                    var str = '';
                    for(var i in d.has_roles) {
                        str += '<span class="layui-badge layui-bg-blue" style="margin-right:5px">'+d.has_roles[i].name+'</span>';
                    }
                    return str;
                }}
                ,{field: 'mobile', title: '手机', width: 120}
                ,{field: 'factory_ids', title: '分配工厂', width: 200, templet:function(d){
                	if (d.factory_ids == '*') return "【全部工厂】";
                	else if(d.factory_ids == '') return "";
                	var factoryIds = d.factory_ids.split(',');
                	var factoryNameArr = [];
                	for (var i in factoryIds){
                		factoryNameArr.push(factoryKV[factoryIds[i]]);
                	}
                	return factoryNameArr.join(' , ');
                }}
                ,{field: 'tags', title: '标签', width: 120}
                ,{field: 'is_online', width: 80, title: '在线',templet:function(d){return layui.tool.formatOnline(d.is_online);}}
                ,{field: 'last_login_time', width: 150, title: '最后登陆'}
                ,{field: 'status', title: '状态', width: 95, templet: '#statusTpl'}
                ,{title: '操作', templet: '#buttonTpl', width:200}
            ]]
        });
    });
</script>